package com.qyhl.module_home.home.panzhou;

import com.orhanobut.hawk.Hawk;
import com.qyhl.webtv.commonlib.entity.home.GatherBean;
import com.qyhl.webtv.commonlib.entity.home.HomeBean;
import com.qyhl.webtv.commonlib.entity.news.AdvHomeBean;

import java.util.List;

public class PanZhouListPresenter implements PanZhouListContract.PanZhouListPresenter {
    private PanZhouListContract.PanZhouListView mView;
    private PanZhouListModel mModel;

    public PanZhouListPresenter(PanZhouListContract.PanZhouListView mView) {
        this.mView = mView;
        this.mModel = new PanZhouListModel(this);
    }

    @Override
    public void getConfig() {
        mModel.getConfig();
    }

    @Override
    public void getGatherData(int page, int lastNewsId, String type) {
        mModel.getGatherData(page, lastNewsId, type);
    }

    @Override
    public void getAdvData() {
        mModel.getAdvData();
    }

    @Override
    public void setConfig(HomeBean bean) {
        mView.setConfig(bean);
    }

    @Override
    public void setGatherNews(List<GatherBean> data, boolean isMore) {
        mView.setGatherNews(data, isMore);
    }

    @Override
    public void setError(int code, String msg) {
        if (code == 1) {
            if (Hawk.contains("home")) {
                HomeBean bean = Hawk.get("home");
                setConfig(bean);//启用缓存数据
            } else {
                mView.showError(msg);
            }
            mView.showMessage(msg);
        } else if (code == 2) {
            mView.showMessage(msg);
        } else if (code == 3) {
            mView.showMessage(msg);
        } else if (code == 4) {
            mView.showMessage(msg);
        } else if (code == 5) {
            mView.showEmpty("无结果！");
        } else {

        }
    }

    @Override
    public void setAdvBanner(List<AdvHomeBean> list) {
        mView.setAdvBanner(list);
    }
}
